/*
	Copyright 2013 Roman Tudor

	This file is part of numbrsLib.

    numbrsLib is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    numbrsLib is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with numbrsLib.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The main package.
 */
package roman.tudor.numbrsLib;
/**
 * A library for numbers.<br />
 * To use this library, give Numbrs.SetNumbr a value and run Numbrs.init()
 * @author <a href="http://romantudorioan.wordpress.com">Tudor Roman</a>
 * @version 2.0
 * @since June 2013
 */
public class Numbrs {
	/** The first processing number */
	private static double processingNr1;
	
	/** The second processing number */
	private static double processingNr2;
	
	/** The third processing number */
	private static double processingNr3;
	
	public static int SetNumbr;
	
	public static Exception nrToBigException;
	static boolean initOk;
	
	private static double n;
	
	/**
	 * Initialises the library<br />
	 * Give Numbrs.SetNumbr a vale before running it.
	 * @author Tudor Roman
	 * @since 2013
	 * @throws Exception
	 */
	public static void init() throws Exception
	{
		n = SetNumbr;
		if (n > 9999)
		{
			throw nrToBigException;
		}
		
		else
		{
			initOk = true;
		}
		
	}
	/**
	 * The thousands.<br />
	 * <b>Example: </b><em><b>1</b>989</em>
	 * @return <code>processingNr3</code>
	 * @throws Exception
	 */
	public static double thousands() throws Exception{
		if (initOk = true)
		{
			
			if (n > 999)
			{
				
				processingNr1 = (int) n / 10;
				processingNr2 = (int) processingNr1 / 10;
				processingNr3 = (int) processingNr2 / 10;
				return processingNr3;
			}
			
		}
		else throw nrToBigException;
		return 0;
		
	}
	/**
	 *The hundreds<br />
	 * <b>Example: </b><em>1<b>9</b>89</em><br />
	 * @return <code>processingNr2, processingNr3</code>
	 * @throws Exception
	 */
	public static double hundreds() throws Exception
	{
		
		if (initOk = true)
		{
			
			if (n > 99 && n < 1000)
			{
				
				processingNr1 = (int) n / 10;
				processingNr2 = (int) processingNr1 / 10;
				return processingNr2;
				
			}
			if (n > 999)
			{
				
				processingNr1 = (int) n / 10;
				processingNr2 = (int) processingNr1 / 10;
				processingNr3 = processingNr2 - (thousands() * 10);
				return processingNr3;
				
			}
			
		}
		else throw nrToBigException;
		
		return 0;
		
	}
	/**
	 * The dozens<br />
	 * <b>Example: </b><i>19<b>8</b>9</i>
	 * @return <code>processingNr1, processingNr2</code>
	 * @throws Exception
	 */
	public static double dozens() throws Exception
	{
		
		if (initOk = true){
	
			if (n > 9 && n < 100)
			{
			
				processingNr1 = (int) n / 10;
				return processingNr1;
			
			}
		
			if (n > 99 && n < 1000)
			{
			
				processingNr1 = (int) n / 10;
				processingNr2 = (int) processingNr1 - hundreds() * 10;
				return processingNr2;
			
			}
		
			if (n > 999)
			{
			
				processingNr1 = (int) n / 10;
				processingNr2 = (int) processingNr1 - thousands() * 100 - hundreds() * 10;
				
				return processingNr2;
		
			}
			
		
		
		}
		else throw nrToBigException;
		return 0;
	}
	/**
	 * The units<br />
	 * <b>Example: </b><i>198<b>9</b></i>
	 * @return <code>processingNr1, processingNr2, processingNr3</code>
	 * @throws Exception
	 */
	public static double units() throws Exception
	{
		if(initOk = true){
			if(n >= 0 && n <= 9){
				return n;
			}
			
			if(n >= 10 && n <= 99){
				processingNr1 = (int) n - (dozens() * 10);
				return processingNr1;
			}
			
			if(n >= 100 && n <= 999){
				processingNr1 = (int) n - (hundreds() * 100);
				processingNr2 = (int) processingNr1 - (dozens() * 10);
				return processingNr2;
			}
			
			if (n >= 1000){
				processingNr1 = (int) n - (thousands() * 1000);
				processingNr2 = (int) processingNr1 - (hundreds() * 100);
				processingNr3 = (int) processingNr2 - (dozens() * 10);
				return processingNr3;
				
			}
		}
		else throw nrToBigException;
		return 0;
		
	}
}
